﻿/****************************************************************************
 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.

 http://www.cocos2d-x.org

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
 ****************************************************************************/

#include "HelloWorldScene.h"
 //#include <iostream>
#include "npc/Bird.h"

USING_NS_CC;

Scene* HelloWorld::createScene()
{
	return HelloWorld::create();
}

// Print useful error message instead of segfaulting when files are not there.
static void problemLoading(const char* filename)
{
	printf("Error while loading: %s\n", filename);
	printf("Depending on how you compiled you might have to add 'Resources/' in front of filenames in HelloWorldScene.cpp\n");
}

bool HelloWorld::init()
{
	//////////////////////////////
	// 1. super init first
	if (!Scene::init())
	{
		return false;
	}

	auto origin = Director::getInstance()->getVisibleOrigin();
	auto winSize = Director::getInstance()->getVisibleSize();


	// 2-1-1-1 基本功能-精灵-精灵创建-方法
	/*
	auto mySprite = Sprite::create("2.png", Rect(0, 0, 200, 200));
	mySprite->setPosition(origin + mySprite->getContentSize() / 2.0f);
	this->addChild(mySprite);
	*/

	// 2-1-1-2 基本功能-精灵-精灵创建-使用图集

	// Texture Packer 工具使用 教程
	/**
	SpriteFrameCache::getInstance()->addSpriteFramesWithFile("forestscene.plist");// 先加载精灵表

	//Vec2 origin = Director::getInstance()->getVisibleOrigin();// 接下来的两行返回屏幕的左下角作为原点，显示的大小作为visibleSize。所有坐标都以设计分辨率返回。您将使用这两个变量在下一个代码块中居中显示背景
	Vec2 visibleSize = Director::getInstance()->getVisibleSize();

	// background
	auto background = Sprite::createWithSpriteFrameName("bg/gamebg.png");// 创建新的Sprite。精灵名称参数是添加到TexturePacker的精灵的名称
	background->setPosition(origin.x + visibleSize.x / 2, origin.y + visibleSize.y / 2); // 为设置位置执行的计算使背景图像在屏幕上居中
	this->addChild(background);// 添加背景对象作为游戏层的子对象

	// Playing animations
	// sprite
	auto frames = getAnimation("role/walk_right/%04d.png", 4);// 创建动画帧
	auto sprite = Sprite::createWithSpriteFrame(frames.front());// 使用列表中的第一帧创建精灵。
	background->addChild(sprite);// 将精灵添加为背景的子对象，而不是场景的子对象。这样可以确保精灵始终位于背景的正确位置。
	sprite->setPosition(100, 620);

	auto animation = Animation::createWithSpriteFrames(frames, 1.0f / 4);//  第二个块使用精灵帧创建动画对象。1.0f / 4是帧速率。它在1秒内播放4帧。确保写入1.0f / 4而不是1 / 4。后者是一个整数除数，结果为0 - 因此动画永远不会播放！
	sprite->runAction(RepeatForever::create(Animate::create(animation)));

	// Moving the sprite
	auto movement = MoveTo::create(10, Vec2(2148, 620));
	auto resetPosition = MoveTo::create(0, Vec2(-150, 620));
	auto sequence = Sequence::create(movement, resetPosition, NULL);
	sprite->runAction(RepeatForever::create(sequence));
	*/

	// 直接用

	/**
	//SpriteFrameCache::getInstance()->addSpriteFramesWithFile("res/birds.plist"); //加载plist文件到一个精灵帧缓存中
	SpriteFrameCache::getInstance()->addSpriteFramesWithFile("birds_.plist");

	// 1.自定义精灵类使用， 不会搞，先搁置！！！
	//auto b1 = new Bird();// 多态
	//b1->setPosition(origin + (b1->getContentSize() / 2.0));
	//this->addChild(b1);// 多态

	// 2.通过精灵帧创建精灵
	//auto b1 = Sprite::createWithSpriteFrameName("blueSprite.png");// 根据精灵帧缓存去找
	//b1->setPosition(origin + (b1->getContentSize() / 2.0));
	//this->addChild(b1);

	// 3.设置精灵节点的时候使用？ 用不了？
	//auto b1 = Sprite::create("res/chapter12/blueSprite.png");

	//auto b1 = new Node();
	//b1->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("LightBlueSprite.png"));
	//b1->setPosition(origin + winSize / 2.0);
	//this->addChild(b1);

	// 4. 帧动画中是使用
	// 5. 播放动画时使用
	// 6. 放进精灵帧使用
	*/

	// 2-1-1-3 基本功能-精灵-精灵创建-使用精灵缓存
	/*
	cocos2d::SpriteFrameCache::getInstance()->addSpriteFramesWithFile("birds_.plist");
	auto b1 = Sprite::createWithSpriteFrameName("5.png");

	//auto b_frame = cocos2d::SpriteFrameCache::getInstance()->getSpriteFrameByName("5.png");// 通过缓存对象获取精灵帧
	//auto b1 = Sprite::createWithSpriteFrame(b_frame);// 用精灵帧创建精灵

	b1->setPosition(origin + winSize / 2.0);
	this->addChild(b1);
	*/


	// 2-1-2 基本功能-精灵-精灵控制
	/**
	cocos2d::SpriteFrameCache::getInstance()->addSpriteFramesWithFile("birds_.plist");
	auto s1 = Sprite::createWithSpriteFrameName("blueSprite.png");
	auto s2 = Sprite::createWithSpriteFrameName("blueSprite.png"); // LightBlueSprite.png
	auto s3 = Sprite::createWithSpriteFrameName("blueSprite.png");// whiteSprite.png
	//s1->setAnchorPoint(Vec2(0, 0));// 左下角
	//s1->setAnchorPoint(Vec2(1, 1));// 右上角
	//s1->setAnchorPoint(Vec2(0, 1));// 左上角

	s1->setPosition(origin + winSize / 2.0 + Vec2(-1.5 * (s1->getContentSize().width), 0));
	s2->setPosition(origin + (winSize / 2.0));
	s3->setPosition(origin + (winSize / 2.0) + Vec2(1.5 * (s3->getContentSize().width), 0));

	// 旋转
	//s1->setRotation(30);// 顺时针绕锚点旋转30度

	// 缩放
	//s1->setScale(1.5);

	// 倾斜

	//       →
	// ←
	//                  30deg
	//s1->setSkewX(30);// |/

	//     ↑
	// ↓
	//                     60
	//s1->setSkewY(30);  // |~/

	// 颜色
	//s1->setColor(Color3B(255, 0, 0));// R
	//s2->setColor(Color3B(0, 255, 0));// G
	//s3->setColor(Color3B(0, 0, 255));// B

	// 透明度 0-255  0(完全透明)-> 255(完全不透明)
	s1->setOpacity(30);
	s2->setOpacity(127.5);
	s3->setOpacity(255);

	this->addChild(s1);
	this->addChild(s2);
	this->addChild(s3);
	*/

	// 2-1-3 基本功能-精灵-多边形精灵
	/*
	// AutoPolygon工具类使用
	auto pinfo = AutoPolygon::generatePolygon("HelloWorld.png");// Generate polygon info automatically. generate success
	//auto pinfo = AutoPolygon::generatePolygon("calendar.png");// PS导出.png的使用不了，估计是size问题
	//auto pinfo = AutoPolygon::generatePolygon("test1_80x80.png");

	auto s1 = Sprite::create(pinfo);//  Create a sprite with polygon info.

	//auto s1 = Sprite::create("test1_80x80.png");//  Create a sprite with polygon info.

	s1->setPosition(origin + winSize / 2.0);
	this->addChild(s1);
	*/

	// 2-2-1 基本功能-动作-基本动作
	/*
	cocos2d::SpriteFrameCache::getInstance()->addSpriteFramesWithFile("birds_.plist");
	auto b1 = Sprite::createWithSpriteFrameName("LightBlueSprite.png");
	b1->setPosition(origin + b1->getContentSize() / 2.0);

	//this->addChild(b1);

	// 移动
	auto moveto = MoveTo::create(0.5, Vec2(100, 100));
	auto moveby = MoveBy::create(0.5, Vec2(100, 100));
	//b1->runAction(Sequence::create(moveto, moveby, nullptr));

	// 旋转
	b1->setPosition(origin + winSize / 2.0);
	auto rotateto = RotateTo::create(2.0f, 45);// 立即旋转到45度
	auto rotateby = RotateBy::create(4.0f, -90);// 当前位置，逆时针旋转90度
	//b1->runAction(Sequence::create(rotateto, rotateby, nullptr));

	// 缩放
	auto b2 = Sprite::createWithSpriteFrameName("LightBlueSprite.png");// 參照
	b2->setPosition(origin + winSize / 2.0);
	b2->setOpacity(127.5);
	b2->setColor(Color3B(255, 0, 0));
	//this->addChild(b2);

	auto scaleto = ScaleTo::create(2.0f, 3.0);// to 3.0x3.0
	auto scaleby = ScaleBy::create(2.0f, 0.5, 0.5);// by 3.0*0.5-> 1.5  1.5x1.5
	auto scaleto1 = ScaleTo::create(2.0f, 1.0f, 0.5f);// to 1.0x0.5
	auto delay = DelayTime::create(1.0);

	//b1->runAction(Sequence::create(delay, scaleto, delay, scaleby, delay, scaleto1, nullptr));


	// 淡入淡出
	auto fadeIn = FadeIn::create(3.0f);// 完全透明->完全不透明 淡入 当前值opacity ->255
	auto fadeOut = FadeOut::create(3.0f);// 完全不透明->完全透明 淡出  当前值opacity ->0
	//b1->setOpacity(0);
	//b1->runAction(Sequence::create(delay, fadeIn, delay, fadeOut, delay, nullptr));

	//auto b3 = Sprite::create("res/chapter12/blueSprite.png");
	//b3->setPosition(origin + winSize / 2.0);
	//this->addChild(b3);
	//b3->runAction(Sequence::create(delay, fadeOut, delay, fadeIn, delay, nullptr));




	// 色彩混合
	auto tintTo = TintTo::create(2.0f, 255.0f, 0.0f, 255.0f);
	auto tintBy = TintBy::create(2.0f, -255.0f, 255.0f, 0.0f); // 增量计算，类似于MoveBy、RotateBy (255.0f, 0.0f, 255.0f) -> (255.0f - 255.0f, 0.0f + 255.0f,255.0f + 0.0f)
	//b1->runAction(Sequence::create(tintTo,delay,tintBy,nullptr));



	// 帧动画——使用 Animate 对象可以很容易的通过每隔一个短暂时间进行图像替代的方式

	SpriteFrameCache::getInstance()->addSpriteFramesWithFile("bird_around.plist");
	Vector<SpriteFrame *> animFrames;
	animFrames.reserve(12);// 提前分配连续内存，防止用pushBack的时候动态改

	// 好麻烦，还要指定第二个参数
	//animFrames.pushBack(SpriteFrame::create("res/chapter4/Blue_Front1.png", Rect(0, 0, 65, 81)));
	//animFrames.pushBack(SpriteFrame::create("res/chapter4/Blue_Front2.png", Rect(0, 0, 65, 81)));
	//animFrames.pushBack(SpriteFrame::create("res/chapter4/Blue_Front3.png", Rect(0, 0, 65, 81)));
	//animFrames.pushBack(SpriteFrame::create("res/chapter4/Blue_Left1.png", Rect(0, 0, 65, 81)));
	//animFrames.pushBack(SpriteFrame::create("res/chapter4/Blue_Left2.png", Rect(0, 0, 65, 81)));
	//animFrames.pushBack(SpriteFrame::create("res/chapter4/Blue_Left3.png", Rect(0, 0, 65, 81)));
	//animFrames.pushBack(SpriteFrame::create("res/chapter4/Blue_Back1.png", Rect(0, 0, 65, 81)));
	//animFrames.pushBack(SpriteFrame::create("res/chapter4/Blue_Back2.png", Rect(0, 0, 65, 81)));
	//animFrames.pushBack(SpriteFrame::create("res/chapter4/Blue_Back3.png", Rect(0, 0, 65, 81)));
	//animFrames.pushBack(SpriteFrame::create("res/chapter4/Blue_Right1.png", Rect(0, 0, 65, 81)));
	//animFrames.pushBack(SpriteFrame::create("res/chapter4/Blue_Right2.png", Rect(0, 0, 65, 81)));
	//animFrames.pushBack(SpriteFrame::create("res/chapter4/Blue_Right3.png", Rect(0, 0, 65, 81)));

	// 使用图集
	animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("Blue_Front1.png"));
	animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("Blue_Front2.png"));
	animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("Blue_Front3.png"));
	animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("Blue_Left1.png"));
	animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("Blue_Left2.png"));
	animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("Blue_Left3.png"));
	animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("Blue_Back1.png"));
	animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("Blue_Back2.png"));
	animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("Blue_Back3.png"));
	animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("Blue_Right1.png"));
	animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("Blue_Right2.png"));
	animFrames.pushBack(SpriteFrameCache::getInstance()->getSpriteFrameByName("Blue_Right3.png"));

	Animation* animation = Animation::createWithSpriteFrames(animFrames,0.05f);
	// 1.0f/20
	//  第二个块使用精灵帧创建动画对象。1.0f / 4是帧速率。它在1秒内播放4帧。确保写入1.0f / 4而不是1 / 4。后者是一个整数除数，结果为0 - 因此动画永远不会播放！
	Animate* animate = Animate::create(animation);


	// 这样写有问题.用节点播放行吗？
	//auto node = Node::create();
	//node->setContentSize(Size(65,81));
	//node->setPosition(origin + winSize / 2.0f);
	//this->addChild(node);
	//node->runAction(RepeatForever::create(animate));

	//b1->runAction(RepeatForever::create(animate));

	// 用第一帧创建精灵 并播放
	//auto mySprite = Sprite::createWithSpriteFrame(animFrames.front());
	//mySprite->setPosition(origin + winSize / 2.0f);
	//this->addChild(mySprite);
	//mySprite->runAction(RepeatForever::create(animate));



	// 变速运动——变速动作可以让节点对象具有加速度，产生平滑同时相对复杂的动作，所以可以用变速动作来模仿一些物理运动，这样比实际使用物理引擎的性能消耗低，使用起来也简单。当然你也可以将变速动作应用到动画菜单和按钮上，实现你想要的效果。

	// 一个精灵从屏幕顶部落下然后不断跳动
	auto newSprite = Sprite::create("res/chapter4/Blue_Front1.png");
	newSprite->setPosition(100, 56);
	auto move = MoveBy::create(2, Point(200, winSize.height - newSprite->getContentSize().height));
	auto move_back = move->reverse();

	auto move_ease_in = EaseBounceIn::create(move->clone());
	auto move_ease_in_back = move_ease_in->reverse();

	auto move_ease_out = EaseBounceOut::create(move->clone());
	auto move_ease_out_back = move_ease_out->reverse();

	delay = DelayTime::create(0.25f);

	auto seq1 = Sequence::create(move_ease_in, delay, move_ease_in_back, delay->clone(), nullptr);

	newSprite->runAction(RepeatForever::create(seq1));
	this->addChild(newSprite);

	//this->addChild(b1);
	*/

	// 2-2-2 基本功能-动作-动作序列
	/*
	// Sequence示例
	SpriteFrameCache::getInstance()->addSpriteFramesWithFile("birds_.plist");
	auto b1 = Sprite::createWithSpriteFrameName("blueSprite.png");
	b1->setPosition(origin + winSize / 2.0);
	this->addChild(b1);

	auto actionJump = JumpTo::create(2.0f, Vec2(origin.x + b1->getContentSize().width / 2.0, origin.y + winSize.height - b1->getContentSize().height / 2.0),100,3);// duration position height(每次跳多高) times(跳几次才到position)
	auto jumpCb = CallFunc::create([] {
		log("jumped!");
	});

	auto actionRotate = RotateTo::create(2.0f, -45);
	auto rotateCb = CallFunc::create([] {
		log("rotated!");
	});
	auto seq1 = Sequence::create(ScaleBy::create(1.0, 2.0), CallFunc::create([] {
		log("Scaled!");
	}), nullptr);

	//b1->runAction(Sequence::create(actionJump, jumpCb, seq1, actionRotate, rotateCb, nullptr));

	// Spawn
	auto actionMoveTo = MoveTo::create(2.0f, Vec2(origin.x + winSize.width - b1->getContentSize().width / 2.0, origin.y + b1->getContentSize().height / 2.0));// 到右下角
	auto actionFadeTo = FadeTo::create(3.0f, 0);

	//b1->runAction(Spawn::createWithTwoActions(actionMoveTo,actionFadeTo));

	// Spawn 的效果和同时运行多个动作的 runAction() 方法是一致的
	//b1->runAction(actionMoveTo);// 异步
	//b1->runAction(actionFadeTo);// 异步

	// 将Spawn放入Sequence中
	auto actionTintTo = TintTo::create(3.0f, Color3B(255, 255, 0));//变色
	auto actionFadeOut = FadeOut::create(2.0f);
	//b1->runAction(Sequence::create(Spawn::create(actionMoveTo, actionTintTo, nullptr), CallFunc::create([] {
	//	log("move and tint over!");
	//}),actionFadeTo, nullptr));// 移动同时变色，接着再淡出


	// 2-2-3 基本功能-动作-动作的克隆和倒转

	// 克隆
	auto actionMoveBy = MoveBy::create(2.0f, Vec2(100, -100));
	//b1->runAction(Sequence::create(actionMoveBy, RotateBy::create(2.0, 360), actionMoveBy->clone(), nullptr));// 右下移动100*100 -> 顺时针旋转一圈 -> 右下移动100*100

	// 倒转
	// reverse a action
	//b1->runAction(actionMoveBy->reverse());// by 倒转右下移动100*100  -> 左上移动100*100
	//b1->runAction(actionMoveTo->reverse());// error: reverse() not supported in MoveTo

	// reverse a sequence
	auto seq2 = Sequence::create(MoveBy::create(2.0f, Vec2(100, -100)), RotateBy::create(2.0, 360), MoveBy::create(2.0f, Vec2(-100, -100)), nullptr);// 右下移动100*100 -> 顺时针旋转360° -> 左下移动100*100
	b1->runAction(seq2->reverse());// 倒转 （序列倒转，方向执行，里面的动作对象也反向执行）-> 右上移动100*100 -> 逆时针旋转一圈 -> 左上移动100*100

	//auto seq2_ = Sequence::create(actionMoveBy, RotateTo::create(2.0, -90), actionMoveBy->clone(), nullptr);
	//b1->runAction(seq2_->reverse());// error: RotateTo doesn't support the 'reverse' method


	// reverse a spawn
	b1->setColor(Color3B(255, 255, 255));
	auto spa1 = Spawn::create(MoveBy::create(1.5f,Vec2(150,150)),TintBy::create(1.5f,100,100,100), ScaleBy::create(1.5f,2.0),nullptr);// 右上移动 + 增量色彩混合 + 放大二倍
	//b1->runAction(spa1->reverse());// 左下移动 + 减量色彩混合 + 缩小二倍


	//b1->runAction(Sequence::create(spa1, spa1->reverse(), nullptr));
	*/

	// 2-3-2-1 基本功能-场景-切换场景-方法
	/*
	SpriteFrameCache::getInstance()->addSpriteFramesWithFile("birds_.plist");
	auto b1 = Sprite::createWithSpriteFrameName("blueSprite.png");
	b1->setPosition(origin + winSize / 2.0);
	this->addChild(b1);

	this->runAction(Sequence::create(DelayTime::create(2.0f), CallFunc::create([] {
		log("release curr scene and load prev scene ...");
		// 释放当前场景，再从场景栈中弹出栈顶的场景，并将其设置为当前运行场景。如果栈为空，直接结束应用。
		Director::getInstance()->popScene();
	}), nullptr));
	*/

	// 2-3-2-2 基本功能-场景-切换场景-切换效果

	//SpriteFrameCache::getInstance()->addSpriteFramesWithFile("birds_.plist");
	//auto b1 = Sprite::createWithSpriteFrameName("LightBlueSprite.png");
	//b1->setPosition(origin + winSize / 2.0);
	//this->addChild(b1);

	auto s1 = Sprite::create("2.png");
	s1->setPosition(origin + winSize / 2.0);
	this->addChild(s1);

	return true;
}

#if false
bool HelloWorld::init()
{
	//////////////////////////////
	// 1. super init first
	if (!Scene::init())
	{
		return false;
	}

	auto origin = Director::getInstance()->getVisibleOrigin();
	/*
	auto s1 = Sprite::create("1.png");
	auto s2 = Sprite::create("2.png");
	auto s3 = Sprite::create("3.png");
	auto s4 = Sprite::create("4.png");
	auto s5 = Sprite::create("5.png");


	s1->setPosition(origin + (s1->getContentSize() / 2.0f));
	s2->setPosition(origin + (s2->getContentSize() / 2.0f));
	s3->setPosition(origin + (s3->getContentSize() / 2.0f));
	s4->setPosition(origin + (s4->getContentSize() / 2.0f));
	s5->setPosition(origin + (s5->getContentSize() / 2.0f));// 左下角
	*/


	//  1-3 基本概念-精灵
	/**
	//this->addChild(s1, -2);// 越小越先渲染，在下面，后渲染的在上面
	//this->addChild(s2, -1);
	//this->addChild(s3); // default z-order 0
	//this->addChild(s4, 1);
	//this->addChild(s5, 2);

	//this->addChild(s1, 2);
	//this->addChild(s2, 2);// 同z-order 先添加的先渲染，在下，

	//s5->setPosition(Vec2(500, 0));// 设置位置
	s5->setPosition(origin + Vec2(0, 0));// 设置位置
	s5->setAnchorPoint(Vec2(0, 0));// 设置锚点，默认(0.5,0.5) 即中心
	s5->setScale(2.0f);// 设置缩放比例
	//s5->setRotation(45);// 顺时针旋转45°
	s5->setRotation(-30);// 逆时针旋转30°

	this->addChild(s5);
	*/

	// 1-4 基本概念-action
	/**
	auto action_1 = MoveTo::create(2.0f, Vec2(100, 100));// 绝对位置，不考虑当前对象位置
	this->runAction(action_1);

	auto action_2 = MoveBy::create(2.0f, Vec2(100, 100));// 相对位置，相对于当前对象位置移动
	s5->runAction(action_2);

	this->addChild(s5);
	*/

	// 1-5 基本概念-sequence
	/**
	//s5->setAnchorPoint(Vec2(0, 0));
	//s5->setPosition(origin + Vec2(0, 0));// action不受锚点影响

	auto s5_contentSize = s5->getContentSize();

	auto action_1 = MoveTo::create(1.0, Vec2(100,100));
	//auto action_1 = MoveTo::create(1.0, Vec2(100 + s5_contentSize.width / 2.0f, 100 + s5_contentSize.height / 2.0f));
	auto action_2 = MoveBy::create(1.0, Vec2(-(100 - origin.x - (s5_contentSize.width / 2.0f)), 100 - origin.y - (s5_contentSize.height / 2.0f)));
	//auto action_2 = MoveBy::create(1.0, Vec2(-100, 100));
	//auto action_2 = MoveBy::create(1.0, Vec2(100, -100));
	auto delay = DelayTime::create(0.5f);

	s5->runAction(Sequence::create(delay, action_1, delay->clone(), action_2, nullptr));// 必须以nullptr结尾,不然报错



	//auto action_2_1 = MoveBy::create(1.0, Vec2(100, 100));
	//s5->runAction(Spawn::create(action_2_1, action_2, nullptr));


	this->addChild(s5);
	*/


	// 1-6 基本概念-节点关系
	/**
	auto b1 = Sprite::create("res/chapter12/blueSprite.png");
	auto b2 = Sprite::create("res/chapter12/LightBlueSprite.png");
	auto b3 = Sprite::create("res/chapter12/whiteSprite.png");

	b1->setPosition(origin + (b1->getContentSize() / 2.0f));// 左下角

	//b2->setPosition(origin + (b2->getContentSize() / 2.0f) + Vec2(0, 100));
	//b3->setPosition(origin + (b3->getContentSize() / 2.0f) + Vec2(100, 0));

	b2->setPosition(origin + (b2->getContentSize() / 2.0f) + Vec2(0, 100));
	b3->setPosition(origin + (b3->getContentSize() / 2.0f) + Vec2(100, 0));

	b1->addChild(b2);
	b1->addChild(b3);

	b1->setRotation(45);

	this->addChild(b1);
	*/

	// 1-7 基本概念-日志输出

	int i = 10;
	log("测试日志整数--%d", i);

	float f = 1.00000f;
	log("测试日志单精度浮点数--%f", f);

	double d = 2.00000;
	log("测试日志双精度浮点数--%f", d);

	std::string s = "test string";
	log("测试日志字符串--%s", s.c_str());

	bool b = true;
	if (b) {
		CCLOG("测试日志布尔值true");
	}
	else {
		CCLOG("测试日志布尔值false");
	}

	std::cout << "test hhh" << std::endl;


	return true;
}
#endif

//
// 此方法从精灵工作表中检索遵循给定格式的动画帧
// Vector frames = getAnimation("role/walk_left/%04d.png", 8);
// 格式字符串 % 04d创建4位数字，前缀为0:0001，0002，0003，。。。
// 调用返回8个精灵帧的列表：role/walk_left/0001.png，。。。role/walk_left/0002.png
// 在返回true之前，将以下代码块添加到HelloWorldScene.cpp中init（）方法的底部：
cocos2d::Vector<cocos2d::SpriteFrame*> HelloWorld::getAnimation(const char *format, int count)
{
	auto spritecache = SpriteFrameCache::getInstance();
	cocos2d::Vector<cocos2d::SpriteFrame*> animFrames;
	char str[100];
	for (int i = 1; i <= count; i++)
	{
		sprintf(str, format, i);
		animFrames.pushBack(spritecache->getSpriteFrameByName(str));
	}
	return animFrames;
}

// on "init" you need to initialize your instance
//bool HelloWorld::init()
//{
//    //////////////////////////////
//    // 1. super init first
//    if ( !Scene::init() )
//    {
//        return false;
//    }
//
//    auto visibleSize = Director::getInstance()->getVisibleSize();
//    Vec2 origin = Director::getInstance()->getVisibleOrigin();
//
//    /////////////////////////////
//    // 2. add a menu item with "X" image, which is clicked to quit the program
//    //    you may modify it.
//
//    // add a "close" icon to exit the progress. it's an autorelease object
//    auto closeItem = MenuItemImage::create(
//                                           "CloseNormal.png",
//                                           "CloseSelected.png",
//                                           CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
//
//    if (closeItem == nullptr ||
//        closeItem->getContentSize().width <= 0 ||
//        closeItem->getContentSize().height <= 0)
//    {
//        problemLoading("'CloseNormal.png' and 'CloseSelected.png'");
//    }
//    else
//    {
//        float x = origin.x + visibleSize.width - closeItem->getContentSize().width/2;
//        float y = origin.y + closeItem->getContentSize().height/2;
//        closeItem->setPosition(Vec2(x,y));
//    }
//
//    // create menu, it's an autorelease object
//    auto menu = Menu::create(closeItem, NULL);
//    menu->setPosition(Vec2::ZERO);
//    this->addChild(menu, 1);
//
//    /////////////////////////////
//    // 3. add your codes below...
//
//    // add a label shows "Hello World"
//    // create and initialize a label
//
//    auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24);
//    if (label == nullptr)
//    {
//        problemLoading("'fonts/Marker Felt.ttf'");
//    }
//    else
//    {
//        // position the label on the center of the screen
//        label->setPosition(Vec2(origin.x + visibleSize.width/2,
//                                origin.y + visibleSize.height - label->getContentSize().height));
//
//        // add the label as a child to this layer
//        this->addChild(label, 1);
//    }
//
//    // add "HelloWorld" splash screen"
//    auto sprite = Sprite::create("HelloWorld.png");
//    if (sprite == nullptr)
//    {
//        problemLoading("'HelloWorld.png'");
//    }
//    else
//    {
//        // position the sprite on the center of the screen
//        sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
//
//        // add the sprite as a child to this layer
//        this->addChild(sprite, 0);
//    }
//    return true;
//}
//
//
//void HelloWorld::menuCloseCallback(Ref* pSender)
//{
//    //Close the cocos2d-x game scene and quit the application
//    Director::getInstance()->end();
//
//    /*To navigate back to native iOS screen(if present) without quitting the application  ,do not use Director::getInstance()->end() as given above,instead trigger a custom event created in RootViewController.mm as below*/
//
//    //EventCustom customEndEvent("game_scene_close_event");
//    //_eventDispatcher->dispatchEvent(&customEndEvent);
//
//
//}
